<?php
/**
 * Magento Enterprise Edition
 *
 * NOTICE OF LICENSE
 *
 * This source file is subject to the Magento Enterprise Edition End User License Agreement
 * that is bundled with this package in the file LICENSE_EE.txt.
 * It is also available through the world-wide-web at this URL:
 * http://www.magento.com/license/enterprise-edition
 * If you did not receive a copy of the license and are unable to
 * obtain it through the world-wide-web, please send an email
 * to license@magento.com so we can send you a copy immediately.
 *
 * DISCLAIMER
 *
 * Do not edit or add to this file if you wish to upgrade Magento to newer
 * versions in the future. If you wish to customize Magento for your
 * needs please refer to http://www.magento.com for more information.
 *
 * @category    design
 * @package     default_default
 * @copyright Copyright (c) 2006-2015 X.commerce, Inc. (http://www.magento.com)
 * @license http://www.magento.com/license/enterprise-edition
 */
?>
<?php
/** @var Enterprise_Support_Block_Adminhtml_Sysreport_Export_Html $this */

/** @var Enterprise_Support_Helper_Data $dataHelper */
$dataHelper = Mage::helper('enterprise_support');
/** @var Enterprise_Support_Helper_Html $htmlHelper */
$htmlHelper = Mage::helper('enterprise_support/html');
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="<?php echo $this->getLang() ?>" lang="<?php echo $this->getLang() ?>">
<head>
    <meta http-equiv="content-type" content="text/html; charset=utf-8" />
    <title>Magento System Report for <?php echo $this->escapeHtml($this->getSysReportTitle()) ?></title>
    <style type="text/css">
        html {
            width: 100%;
        }
        body {
            line-height:1.0em;
            font: 13px/1.5em Arial,Helvetica,sans-serif;
        }
        table {
            border-collapse: collapse;
            margin:0;
            padding:0
        }
        th {
            text-align: center;
            font-weight: bold;
            padding: 10px;
            border: 1px solid black;
            background-color: #7eadd9
        }
        td {
            text-align: left;
            padding: 7px;
            border: 1px solid black;
            vertical-align: top
        }
        h1, h2, h3, h4 {
            margin-bottom:.5em; line-height:1.4em;
        }
        h2 {
            font-size:1.7em
        }
        h3 {
            margin-bottom:.5em; color:#253033; font-size:1.25em
        }
        h4 {
            margin-bottom:.6em; color:#494848; font-size:1.05em
        }
        h5 {
            font-size:1.05em
        }
        h6 {
            font-size:1em
        }
        h1 a, h1 a:hover,
        h2 a, h2 a:hover,
        h3 a, h3 a:hover,
        h4 a, h4 a:hover {
            font-weight:normal
        }
        .flag-yes, .flag-processing, .flag-no {
            font-weight: bold;
            text-align: center;
            vertical-align: middle;
            color: #FFFFFF
        }
        .flag-yes {
            background-color: #00BD39;
        }
        .flag-processing {
            background-color: #FF9640;
        }
        .flag-no {
            background-color: #FF4040;
        }
        .selected-row td, tr:hover td {
            background-color: #FFE7A1;
            color: #000000
        }
        .report-cell-text {
            display: none;
        }
        a, a:visited {
            color: #0044ff
        }
        a:hover {
            background-color: #FFE7A1;
            color: #000000
        }
        h1#report-title span {
            color: #205791
        }
        div#copyright {
            width: 100%;
            text-align: left;
            color: #6a6a6a;
            font-size: 80%
        }
        .file-path {
            color: #6a6a6a;
            font-size: 80%
        }
        .diff-negative {
            color: #FF4040;
            font-weight: bold;
        }
        .diff-positive {
            color: #00BD39;
            font-weight: bold;
        }

        /* Menu */
        #report-menu:after {
            clear: both;
            content: ".";
            display: block;
            font-size: 0;
            height: 0;
            line-height: 0;
            overflow: hidden;
        }
        #report-menu {
            background: none repeat scroll 0 0 #97c8f5;
            left: 0;
            position: fixed;
            top: 0;
            width: 100%;
            z-index: 100;
            border-bottom: 1px solid #6a6a6a
        }
        #report-menu ul {
            margin: 0;
            padding:0;
            list-style:none;
        }
        #report-menu ul li  {
            margin:0;
            position:relative;
            height:30px;
            line-height:30px;
        }
        #report-menu ul li a, span.report-menu-root-item {
            display: block;
            text-decoration: none;
            color: #000;
            padding: 0 5px;
            border-left: none;
            background-color: #97c8f5;
        }
        span.report-menu-root-item:hover {
            cursor: pointer;
            background-color: #FFE7A1;
        }
        #report-menu > ul > li {
            float: left;
            height: 30px;
            line-height: 30px;
        }
        #report-menu li > ul {
            visibility:hidden;
            width: 280px;
            position: absolute;
            top:0;
            border-left: 1px solid #000;
        }
        #report-menu > ul > li > ul {
            top:30px;
            left:0;
        }
        #report-menu a:hover{
            background-color: #FFE7A1;
        }
        #report-menu li:hover > ul {
            visibility:visible;
        }
        * html #report-menu ul li { float: left; height: 1%; }
        * html #report-menu ul li a { height: 1%; }
        a.no-data-link {
            color: #597aa3 !important;
        }
        a#top-link {
            background-color: #FFE7A1 !important;
            font-weight: bold !important
        }
    </style>
    <script type="text/javascript">
        function toggleTableData(element, tableId)
        {
            var tableDiv = document.getElementById(tableId);
            if (tableDiv.style.display == 'none') {
                tableDiv.style.display = 'block';
                element.firstChild.data = '<?php echo $this->jsQuoteEscape($this->__('Collapse')) ?>';
            } else {
                tableDiv.style.display = 'none';
                element.firstChild.data = '<?php echo $this->jsQuoteEscape($this->__('Expand')) ?>';
            }
        }

        function showFullText(cellId)
        {
            var cellObject = document.getElementById(cellId);
            var fullTextDiv = cellObject.getElementsByClassName('report-cell-text')[0];
            cellObject.innerHTML = fullTextDiv.innerHTML;

        }

        window.onload = function()
        {
            var rows = document.getElementsByTagName('tr');
            for (var i = 0; i < rows.length; i++) {
                var row = rows[i];
                row.onclick = function () {
                    var tds = this.childNodes;
                    for (var j = 0; j < tds.length; j++) {
                        if (tds[j].className.indexOf('selected-row') !=-1) {
                            tds[j].className = tds[j].className.replace('selected-row', '');
                        } else {
                            tds[j].className += ' selected-row';
                        }
                    }
                }
            }
        }
    </script>
</head>
<body>
<a name="top">&nbsp;</a><br />
<div id="report-menu">
    <ul>
<?php
$html = '';
$reportByTypes = $this->getReportByTypes();

foreach ($reportByTypes as $type) {
    if (empty($type['reports'])) {
        continue;
    }
    $html .= '<li><span class="report-menu-root-item">' . htmlspecialchars($type['title']) . '</span><ul>';

    foreach ($type['reports'] as $title => $data) {
        $dataNumber = $dataHelper->getSysReportDataCount($data);
        $html .= '<li><a href="#' . md5($title) . '"' . (!$dataNumber ? ' class="no-data-link"' : '') . '>'
            . htmlspecialchars($dataHelper->getReportTitle($title))
            . ($dataNumber > 0 ? ' (' . $dataNumber . ')' : $this->__(' (no data)'))
            . '</a></li>';
    }

    $html .= '</ul></li>';
}
$html .= '<li><a href="#top" id="top-link">' . $this->__('Top') . '</a></li>';

echo $html;
?>
    </ul>
</div>
<h1 id="report-title">Magento System Report for <span><?php echo $this->escapeHtml($this->getSysReportTitle()) ?></span> on <?php echo $this->escapeHtml($this->getSysReportCreateDate()) ?></h1>
<?php
$counter = 1;
$html = '';
foreach ($reportByTypes as $type) {
    if (empty($type['reports'])) {
        continue;
    }
    foreach ($type['reports'] as $title => $data) {
        $report = $header = '';
        $dataNumber = $dataHelper->getSysReportDataCount($data);

        if (is_array($data) && !empty($data) && !empty($data['header']) && !empty($data['data'])) {
            $_preparedHeader = $data['header'];
            $_preparedData = $data['data'];
            if (!empty($_preparedHeader)) {
                foreach ($_preparedHeader as $text) {
                    $text = htmlspecialchars($dataHelper->getReportColumnLabel($text));
                    $header .= '<th>'
                        . str_replace(array("\n", "\r"), '<br />', $text)
                        . '</th>';
                }
            }

            if (!empty($_preparedData)) {
                foreach ($_preparedData as $rowId => $row) {
                    $report .= '<tr>';
                    foreach ($row as $columnId => $text) {
                        $rawText = $text;
                        $text = $dataHelper->getReportValueText($text);
                        $report .= $htmlHelper->getExportTableCellHtml(
                            $text,
                            $rawText,
                            md5($title . $rowId . $columnId)
                        );
                    }
                    $report .= '</tr>';
                }
            }
        } else {
            $report .= '<tr><td>' . $this->__('No data') . '</td></tr>';
        }

        $anchor = md5($title);
        $title = htmlspecialchars($dataHelper->getReportTitle($title));
        $expandFlag = $dataNumber > Enterprise_Support_Helper_Data::SYSREPORT_DATA_MAX_NONE_COLLAPSIBLE_ROW_COUNT;
        $html .= "
    <a name=\"$anchor\">&nbsp;</a><br />

    <h2>$counter. $title: ($dataNumber)"
                . ($expandFlag ? ' | <a href="javascript:void(0);" onclick="toggleTableData(this, \'table_'
                    . $anchor
                    . '\')">' . $this->__('Expand') . '</a>' : '')
                . "</h2>
    <div id=\"table_$anchor\" style=\"" . ($expandFlag ? 'display: none' : '') . "\">
        <table class=\"report-table\">
            <thead>
                <tr>
                    $header
                </tr>
            </thead>
            <tbody>
                $report
            </tbody>
        </table>
    </div>
";
        $counter++;
    }
}

echo $html;
?>
<br />
<br />
<div id="copyright"><?php echo $this->getCopyrightText() ?></div>
</body>
</html>
